import { http } from '@/api/http'
import { httpErrorHandle } from '@/utils'
import { RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
import { LoginResult } from './system'

// * 登录
export const loginApi = async (data: object) => {
  try {
    const res: any = await http(RequestHttpEnum.POST)<LoginResult>(`/user/login`, data, 'application/x-www-form-urlencoded' as any)
    return res
  } catch (err) {
    console.log(err)
    httpErrorHandle()
  }
}

// * 登出
export const logoutApi = async () => {
  try {
    const res = await http(RequestHttpEnum.GET)(`${ModuleTypeEnum.SYSTEM}/logout`)
    return res
  } catch (err) {
    httpErrorHandle()
  }
}

// * 获取 oss 上传接口
export const ossUrlApi = async (data: object) => {
  // try {
  //   const res = await http(RequestHttpEnum.GET)<{
  //     /**
  //      * bucket 地址
  //      */
  //     bucketURL?: string
  //   }>(`${ModuleTypeEnum.SYSTEM}/getOssInfo`, data)
  //   return res
  // } catch (err) {
  //   httpErrorHandle()
  // }
}

export const companyListApi = async (data?: object) => {
  try {
    const res = await http(RequestHttpEnum.POST)(`/user/list`, data)
    return res
  } catch (err) {
    httpErrorHandle()
  }
}


// * 保存公司
export const saveCompanyApi = async (data: object) => {
  try {
    const res = await http(RequestHttpEnum.POST)(`user/save`, data)
    return res
  } catch {
    httpErrorHandle()
  }
}


export const companyDeleteApi = async (data: object) => {
  try {
    const res = await http(RequestHttpEnum.POST)(`/user/delete`, data)
    return res
  } catch (err) {
    httpErrorHandle()
  }
}
